package com.ruoyi.web.controller.commodity;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.commodity.domain.vo.QualityTemplateVO;
import com.ruoyi.commodity.mapper.ProductImageMapper;
import com.ruoyi.commodity.mapper.ProductImagesMapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.commodity.domain.QualityTemplate;
import com.ruoyi.commodity.service.IQualityTemplateService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 质检模板Controller
 * 
 * @author luxiaoyu
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/commodity/template")
public class QualityTemplateController extends BaseController
{
    @Autowired
    private IQualityTemplateService qualityTemplateService;
    /**
     * 查询质检模板列表
     */
    @PreAuthorize("@ss.hasPermi('commodity:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(QualityTemplate qualityTemplate)
    {
        startPage();
        List<QualityTemplateVO> list = qualityTemplateService.selectQualityTemplateList(qualityTemplate);
        return getDataTable(list);
    }

    /**
     * 查询质检模板列表
     */
    @GetMapping("/template/list")
    public TableDataInfo templateList(QualityTemplate qualityTemplate)
    {
        List<QualityTemplateVO> list = qualityTemplateService.selectQualityTemplateList(qualityTemplate);
        return getDataTable(list);
    }

    /**
     * 导出质检模板列表
     */
    @PreAuthorize("@ss.hasPermi('commodity:template:export')")
    @Log(title = "质检模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualityTemplate qualityTemplate)
    {
        List<QualityTemplateVO> list = qualityTemplateService.selectQualityTemplateList(qualityTemplate);
        ExcelUtil<QualityTemplateVO> util = new ExcelUtil<QualityTemplateVO>(QualityTemplateVO.class);
        util.exportExcel(response, list, "质检模板数据");
    }

    /**
     * 获取质检模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('commodity:template:query')")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Long templateId)
    {
        return success(qualityTemplateService.selectQualityTemplateByTemplateId(templateId));
    }

    /**
     * 新增质检模板
     */
    @PreAuthorize("@ss.hasPermi('commodity:template:add')")
    @Log(title = "质检模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QualityTemplateVO qualityTemplate)
    {
        return toAjax(qualityTemplateService.insertQualityTemplate(qualityTemplate));
    }

    /**
     * 修改质检模板
     */
    @PreAuthorize("@ss.hasPermi('commodity:template:edit')")
    @Log(title = "质检模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualityTemplateVO qualityTemplateVO)
    {
        return toAjax(qualityTemplateService.updateQualityTemplate(qualityTemplateVO));
    }

    /**
     * 删除质检模板
     */
    @PreAuthorize("@ss.hasPermi('commodity:template:remove')")
    @Log(title = "质检模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Long[] templateIds)
    {
        return toAjax(qualityTemplateService.deleteQualityTemplateByTemplateIds(templateIds));
    }
}
